package by.grsu.shedule.adapter;

import java.util.List;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import by.grsu.shedule.R;
import by.grsu.shedule.common.adapter.CommonFragmentPagerAdapter;
import by.grsu.shedule.fragment.DayFragment;
import by.grsu.shedule.util.CalendarHelper;

import com.viewpagerindicator.TitleProvider;

public class MainAdapter extends CommonFragmentPagerAdapter implements
		TitleProvider {

	private Context context;

	private List<String> dateList;



	public MainAdapter(FragmentManager fm, Context context) {
		super(fm);
		this.context = context;
		this.dateList = CalendarHelper.getCurrentDateList();
		initFragments();
	}

	@Override
	public String getTitle(int position) {
		return context.getResources().getStringArray(R.array.days_full)[position];
	}

	public void initFragments() {
		for (int i = 0; i < 6; i++) {
			getFragments().add(DayFragment.newInstance(dateList.get(i)));
		}
	}

	public void refreshData() {

		List<String> dateList = CalendarHelper.getCurrentDateList();
		for (int i = 0; i < 6; i++) {
			((DayFragment) getFragments().get(i)).refreshData(dateList.get(i));
		}
	}
	
	public void clearData(){
		for(int i=0;i<6;i++){
			((DayFragment) getFragments().get(i)).clearData();
		}
	}

	

}
